package com.tender.controller;

import com.tender.RouterDiscoveryBizService;
import com.tender.common.Result;
import com.tender.dto.HostInfoDTO;
import com.tender.enums.ServiceTypeEnums;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("api/ws/op/router")
public class RouterDiscoveryController {

    @Autowired
    private RouterDiscoveryBizService routerDiscoveryBizService;

    @GetMapping("/ws/random")
    public Result<HostInfoDTO > randomWsInfo() {
        Result<HostInfoDTO > result = Result.success();
        result.setData(routerDiscoveryBizService.getHostInfo(ServiceTypeEnums .WS.name(), null));
        return result;
    }

    @GetMapping("/ws/all")
    public Result<List<HostInfoDTO >> wsHostInfoList() {
        return Result.success(routerDiscoveryBizService.getHostInfoList(ServiceTypeEnums.WS.name(), null));
    }

    @GetMapping("/common/all/{applicationName}")
    public Result<List<HostInfoDTO >> commonHostInfoList(@PathVariable String applicationName) {
        return Result.success(routerDiscoveryBizService.getHostInfoList(ServiceTypeEnums.COMMON.name(), applicationName));
    }

    @GetMapping("/ws/{userId}")
    public Result<HostInfoDTO > randomWsInfoByUserId(@PathVariable("userId") String userId) {
        return Result.success(routerDiscoveryBizService.randomWsInfoByUserId(userId));
    }

}
